import axios from 'axios';
// 环境的切换
  //开发模式
axios.defaults.baseURL = process.env.NODE_ENV == 'development'?'/api':window.frontUrl;
axios.defaults.timeout = 5000;
/**
 * 封装get方法
 * @param url
 * @param data
 * @returns {Promise}
 */

export function get(url,params={},headers={}){
  return new Promise((resolve,reject) => {
    axios.get(url,{
      params:params
    },{'headers':headers})
      .then(response => {
        resolve(response.data);
      })
      .catch(err => {
        reject(err)
      })
  })
}


/**
 * 封装post请求
 * @param url
 * @param data
 * @returns {Promise}
 */

export function post(url,data = {},headers={}){
  return new Promise((resolve,reject) => {
    axios.post(url,data,{'headers':headers})
      .then(response => {
        resolve(response.data);
      },err => {
        reject(err)
      })
  })
}
